package com.uxhao.eduservice.controller;


import com.uxhao.commonutils.R;
import com.uxhao.eduservice.entity.EduVideo;
import com.uxhao.eduservice.service.EduVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 课程视频 前端控制器
 * @author uxhao
 * @since 2022/01/11
 */
@Api(tags = {"小节管理"})
@RestController
//@CrossOrigin
@RequestMapping("/eduservice/video")
public class EduVideoController {

    @Autowired
    private EduVideoService eduVideoService;


    @ApiOperation(value = "新增课时")
    @PostMapping("save")
    public R save(
            @ApiParam(name = "videoForm", value = "课时对象", required = true)
            @RequestBody EduVideo videoInfoForm) {

        eduVideoService.save(videoInfoForm);
        return R.ok();
    }

    @ApiOperation(value = "根据ID删除课时和视频")
    @DeleteMapping("{id}")
    public R removeById(
            @ApiParam(name = "id", value = "课时ID", required = true)
            @PathVariable String id) {

        boolean result = eduVideoService.removeVideoById(id);
        return result ? R.ok() : R.error().message("删除失败");

    }

    @ApiOperation(value = "根据ID查询课时")
    @GetMapping("{id}")
    public R getVideoInfoById(
            @ApiParam(name = "id", value = "课时ID", required = true)
            @PathVariable String id) {

        EduVideo videoInfoForm = eduVideoService.getById(id);
        return R.ok().data("item", videoInfoForm);
    }

    @ApiOperation(value = "更新课时")
    @PostMapping("updateVideo/{id}")
    public R updateVideo(
            @ApiParam(name = "VideoInfoForm", value = "课时基本信息", required = true)
            @RequestBody EduVideo videoInfoForm) {

        eduVideoService.updateById(videoInfoForm);
        return R.ok();
    }


}

